package cloudnative.demo.labclient.controller;

import cloudnative.demo.labclient.client.PersonnelServiceClient;
import cloudnative.demo.labclient.model.Manager;
import cloudnative.demo.labclient.model.Student;
import cloudnative.demo.labclient.model.Teacher;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@AllArgsConstructor
@RestController
@Slf4j
@RequestMapping("/personnel")
public class PersonnelServiceClientController {


    @Autowired
    private PersonnelServiceClient personnelServiceClient;


    // 增加教师接口
    @PostMapping("/addT")
    public void addTeacher(@RequestBody Teacher teacher) {
        personnelServiceClient.addTeacher(teacher);
    }

    // 增加学生接口
    @PostMapping("/addS")
    public void addStudent(@RequestBody Student student) {
        personnelServiceClient.addStudent(student);
    }

    // 增加管理员接口
    @PostMapping("/addM")
    public void addManager(@RequestBody Manager manager) {
        personnelServiceClient.addManager(manager);
    }

    // 查询所有教师
    @GetMapping("/queryT")
    public List<Teacher> queryAllTeachers() {
        try{
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        log.info("-------------OK   //queryT--------------------");
        return personnelServiceClient.queryAllTeachers();
    }

    // 查询所有学生
    @GetMapping("/queryS")
    public List<Student> queryAllStudents() {
        try{
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        log.info("-------------OK   //queryS--------------------");
        return personnelServiceClient.queryAllStudents();
    }

    // 查询所有管理员
    @GetMapping("/queryM")
    public List<Manager> queryAllManagers() {
        try{
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        log.info("-------------OK   //queryM--------------------");
        return personnelServiceClient.queryAllManagers();
    }

    // 按名字和ID查询学生
    @PostMapping("/querySBNID")
    public List<Student> queryStudentByNameAndId(@RequestBody Student student) {
        return personnelServiceClient.queryStudentByNameAndId(student);
    }

    // 按名字和ID查询管理员
    @PostMapping("/queryMBNID")
    public List<Manager> queryManagerByNameAndId(@RequestBody Manager manager) {
        return personnelServiceClient.queryManagerByNameAndId(manager);
    }

    // 按名字和ID查询教师
    @PostMapping("/queryTBNID")
    public List<Teacher> queryTeacherByNameAndId(@RequestBody Teacher teacher) {
        return personnelServiceClient.queryTeacherByNameAndId(teacher);
    }

    // 删除教师接口
    @PostMapping("/deleteT")
    public void deleteTeacher(@RequestBody Teacher teacher) {
        personnelServiceClient.deleteTeacher(teacher);
    }

    // 删除学生接口
    @PostMapping("/deleteS")
    public void deleteStudent(@RequestBody Student student) {
        personnelServiceClient.deleteStudent(student);
    }

    // 删除管理员接口
    @PostMapping("/deleteM")
    public void deleteManager(@RequestBody Manager manager) {
        personnelServiceClient.deleteManager(manager);
    }

    // 更新教师信息
    @PostMapping("/alterT")
    public void updateTeacher(@RequestBody Teacher teacher) {
        personnelServiceClient.updateTeacher(teacher);
    }

    // 更新学生信息
    @PostMapping("/alterS")
    public void updateStudent(@RequestBody Student student) {
        personnelServiceClient.updateStudent(student);
    }

    // 更新管理员信息
    @PostMapping("/alterM")
    public void updateManager(@RequestBody Manager manager) {
        personnelServiceClient.updateManager(manager);
    }
}
